﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Applay
{
    public abstract class Service : MarshalByRefObject
    {
        private Wrapper wrapper;

        internal void Initialize(Wrapper wrapper)
        {
            Contract.Requires(wrapper != null);

            this.wrapper = wrapper;
        }

        public IValidationState ModelState
        {
            get
            {
                if (wrapper == null)
                {
                    throw new InvalidOperationException("Cannot access validation state. The service has not been initialized.");
                }

                if (wrapper.ValidationScope == null)
                {
                    throw new InvalidOperationException("Cannot access validation state. Missing validation scope.");
                }

                return this.wrapper.ValidationScope.ValidationState;
            }
        }
    }
}
